package com.hzk.controller;

import com.hzk.exception.GabalException;
import com.hzk.pojo.Order;
import com.hzk.pojo.UserBasic;
import com.hzk.service.IGoodsService;
import com.hzk.service.IOrderService;
import com.hzk.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jack
 * @since 2022-03-01
 */
@Controller
@RequestMapping("/order")
@ResponseBody
public class OrderController {
    @Autowired
    IOrderService iOrderService;
    @Autowired
    IGoodsService iGoodsService;

    @RequestMapping("/detail")
    public RespBean detail(@CaseUser UserBasic userBasic, Long orderId) {
        if (userBasic == null) {
            throw new GabalException(RespBeanEnum.NULL_USER_ERROR);
        }
        Order order = iOrderService.detail(userBasic, orderId);
        GoodsVo goods = iGoodsService.findGoodsByid(order.getGoodsId());
        OrderDetailVo detail = new OrderDetailVo(goods, order);
        return RespBean.success(detail);
    }
}
